package cn.com.woxitech.dev.common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

public class StrUtils {
	
	public static int strToInt(String s, int default_val){
		int v = default_val;
		try{
			
			v = Integer.parseInt(s);
			
		}catch(Exception e){
			v = default_val;
		}
		return v;
		
	}
	public static String Inputstr2Str_Reader(InputStream in, String encode)
    {
        
        String str = "";
        try
        {
            if (encode == null || encode.equals(""))
            {
                // 默认以utf-8形式
                encode = "utf-8";
            }
            BufferedReader reader = new BufferedReader(new InputStreamReader(in, encode));
            StringBuffer sb = new StringBuffer();
            
            while ((str = reader.readLine()) != null)
            {
                sb.append(str).append("\n");
            }
            return sb.toString();
        }
        catch (UnsupportedEncodingException e1)
        {
            e1.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        
        return str;
    }
	public static String removeVirguleOfEnd(String val) {//去掉 ／ 号
		// TODO Auto-generated method stub
		
		if(val.substring(val.length()-1).equals("/")){
			return val.substring(0,val.length()-1);
		}
		return val;
	}
	public static String getMapStr(String key, Map<String, Object> mp) {
		// TODO Auto-generated method stub
		return (mp.get(key)==null?null:(String)(mp.get(key))+"");
	}
}
